package com.thtf.homework.mapper;

import com.thtf.homework.model.DataSource;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;

@Mapper
public interface DataSourceMapper {

    // 添加数据源
    @Insert("""
                    INSERT INTO "LIWEIJIE"."T_SJYGL_SJY" ("SJYJG", "SJYLX", "TBLJ", "SJYFL", "SJYMC", "URL", 
                                                      "USERNAME", "PASSWORD", "MODE", "DESCRIPTION",
                                                      "CJSJ", "ZHXGSJ", "SFSC", "SJYBH") VALUES (#{dataSourceStruct}, #{dataSourceType}, 'src\\assets\\images\\Dameng.png',
                                                                            #{dataSourceClassification}, #{dataSourceName},\
                     #{dataSourceURL}, #{dataSourceUsername}, #{dataSourcePassword}, #{dataSourceMode},\
                     #{dataSourceDescription}, now(), now(), 'F', #{dataSourceId})
            """)
    void add(String dataSourceStruct, String dataSourceType, String dataSourceClassification, String dataSourceName,
             String dataSourceURL, String dataSourceUsername, String dataSourcePassword, String dataSourceMode,
             String dataSourceDescription, String dataSourceId);


    // 查询数据源
    @Select("""
                SELECT  "SJYJG", "SJYLX", "TBLJ", "SJYFL", "SJYMC", "URL", 
                                                  "USERNAME", "MODE", "DESCRIPTION",
                                                  "CJSJ", "ZHXGSJ", "SFSC", "SJYBH" FROM "LIWEIJIE"."T_SJYGL_SJY" 
                                                                    WHERE "SJYFL" = #{dataSourceClassification} 
                                                              AND "SFSC" = 'F';    
            """)
    List<DataSource> query(String dataSourceClassification);


    @Update("""
                     UPDATE "LIWEIJIE"."T_SJYGL_SJY"
            SET\s
                "SJYFL" = #{dataSourceClassification},
                "SJYMC" = #{dataSourceName},
                "URL" = #{dataSourceURL},
                "USERNAME" = #{dataSourceUsername},
                "PASSWORD" = #{dataSourcePassword},
                "MODE" = #{dataSourceMode},
                "DESCRIPTION" = #{dataSourceDescription},
                "ZHXGSJ" = now()
            WHERE "SJYBH" = #{dataSourceId};
            """)
    void update(String dataSourceClassification, String dataSourceName, String dataSourceURL, String dataSourceUsername,
                String dataSourcePassword, String dataSourceMode, String dataSourceDescription, String dataSourceId);

    @Update("""
                     UPDATE "LIWEIJIE"."T_SJYGL_SJY"
                        SET\s
                "SFSC" = 'T',
                "ZHXGSJ" = now()
                        WHERE "SJYBH" = #{dataSourceId};
            """)
    void delete(String dataSourceId);

}

